
// 加载元素控件
var $ = '';
layui.use(['jquery', 'table', 'form', 'layer','laydate'], function(){
    var customerid = QueryUtils.GetQueryString("id");
    var form = layui.form,layer = layui.layer,$ = layui.jquery;
    $("#id").val(customerid);
   /* laydate = layui.laydate;
    laydate.render({
        elem: '#FIR_VISIT_DATE'
        , format: 'yyyy-MM-dd'
    });*/
   /* laydate.render({
        elem: '#FOLLOW_DATE'
        , format: 'yyyy-MM-dd'
    });*/
    $.ajax({
        url: "/customer/info",
        data: {ID:customerid},
        dataType: "json",
        type: "post",
        async: false,
        success: function (res) {
                if (res.errcode === "0") {
                   $("input[name='BUDING_NAME']").val(res.data.BUDING_NAME);
                    $("input[name='COMPANY']").val(res.data.COMPANY);
                    if(res.data.TRADE=="1")
                    {
                        var str1 = '<option value="' + res.data.TRADE + '" selected>' + "软件开发" +'</option>';
                        var str2 = '<option value="2" selected>' + "楼房销售" +'</option>';
                        var str3 = '<option value="3" selected>' + "楼房租聘" +'</option>';
                        $("select[name='TRADE']").append(str1);
                        $("select[name='TRADE']").append(str2);
                        $("select[name='TRADE']").append(str3);
                    }else if (res.data.TRADE=="2"){
                        var str1 = '<option value="1" selected>' + "软件开发" +'</option>';
                        var str2 = '<option value="' + res.data.TRADE + '" selected>' + "楼房销售" +'</option>';
                        var str3 = '<option value="3" selected>' + "楼房租聘" +'</option>';
                        $("select[name='TRADE']").append(str1);
                        $("select[name='TRADE']").append(str2);
                        $("select[name='TRADE']").append(str3);
                    } else if (res.data.TRADE=="3"){
                        var str1 = '<option value="1" selected>' + "软件开发" +'</option>';
                        var str2 = '<option value="2" selected>' + "楼房销售" +'</option>';
                        var str3 = '<option value="' + res.data.TRADE + '" selected>' + "楼房租聘" +'</option>';
                        $("select[name='TRADE']").append(str1);
                        $("select[name='TRADE']").append(str2);
                        $("select[name='TRADE']").append(str3);
                    }
                    $("input[name='FIR_VISIT_DATE']").val(res.data.FIR_VISIT_DATE);
                    $("input[name='CONTACT']").val(res.data.CONTACT);
                    $("input[name='CONTACT_TEL']").val(res.data.CONTACT_TEL);
                    $("input[name='LEG_REN']").val(res.data.LEG_REN);
                    $("input[name='LEG_TEL']").val(res.data.LEG_TEL);
                    $("input[name='SIGN_REN']").val(res.data.SIGN_REN);
                    $("input[name='SIGN_TEL']").val(res.data.SIGN_TEL);
                    $("input[name='BUSS_CODE']").val(res.data.BUSS_CODE);
                    $("input[name='ADDRESS']").val(res.data.ADDRESS);
                    if(res.data.ALL_WAY=="1")
                    {


                        var str1 = '<option value="' + res.data.ALL_WAY + '" selected>' + "上门" +'</option>';
                        var str2 = '<option value="2" selected>' + "电话" +'</option>';
                        var str3 = '<option value="3" selected>' + "其他" +'</option>';
                        $("select[name='ALL_WAY']").append(str1);
                        $("select[name='ALL_WAY']").append(str2);
                        $("select[name='ALL_WAY']").append(str3);
                    }else if (res.data.ALL_WAY=="2"){

                        var str1 = '<option value="1" selected>' + "上门" +'</option>';
                        var str2 = '<option value="' + res.data.ALL_WAY + '" selected>' + "电话" +'</option>';
                        var str3 = '<option value="3" selected>' + "其他" +'</option>';
                        $("select[name='ALL_WAY']").append(str1);
                        $("select[name='ALL_WAY']").append(str2);
                        $("select[name='ALL_WAY']").append(str3);
                    } else if (res.data.ALL_WAY=="3"){

                        var str1 = '<option value="1" selected>' + "上门" +'</option>';
                        var str2 = '<option value="2" selected>' + "电话" +'</option>';
                        var str3 = '<option value="' + res.data.ALL_WAY + '" selected>' + "其他" +'</option>';
                        $("select[name='ALL_WAY']").append(str1);
                        $("select[name='ALL_WAY']").append(str2);
                        $("select[name='ALL_WAY']").append(str3);
                    }
                    $("input[name='DEMAN_AREA']").val(res.data.DEMAN_AREA);
                    $("input[name='FOLLOW_DATE']").val(res.data.FOLLOW_DATE);
                    $("input[name='LEAS_CONS']").val(res.data.LEAS_CONS);
                    $("input[name='CUS_INFO']").val(res.data.CUS_INFO);
                    form.render("select");
            } else if (res.errcode === "1"){
                layer.msg(res.errmsg, function(){});
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            console.error(XMLHttpRequest.status);
            console.error(XMLHttpRequest.readyState);
            console.error(textStatus);
        }
    });
    //监听提交
    form.on('submit(demo1)', function(data){
       /* console.log(data.field);*/
        var data1=data.field;
        /*console.log(data1);*/
        layer.msg('确认修改客户吗', {
            time: 0
            , btn: ['确定', '取消']
            , shade: 0.3
            , yes: function (data) {
                $.ajax({
                    url: "/customer/editx",
                    data: data1,
                    type: "Post",
                    dataType: "json",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            var index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
                            parent.layer.close(index); // 再执行关闭
                            // window.parent.location.reload();
                            parent.reloadTablezs();// 父页面表格刷新
                            layer.msg("保存成功");
                        }
                    }
                });
            },
        })
        return false;
    });
});

